<!-- toast组件 -->
<template>
  <div class="toast" v-if="isShow">
    <p>{{ message }}</p>
  </div>
</template>

<script>
export default {
  name: 'Toast',
  data() {
    return {
      message: '',
      isShow: false,
    };
  },
  components: {},
  methods: {
    show(message = '这是一个模态框', timeout = 1500) {
      this.message = message;
      this.isShow = true;
      setTimeout(() => {
        this.isShow = false;
        this.message = '';
      }, timeout);
    },
  },
};
</script>

<style scoped>
.toast {
  max-width: 180px;
  padding: 6px 8px;
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 99;
  transform: translate(-50%, -50%);
  font-size: 0.8rem;
  color: white;
  background-color: rgba(0, 0, 0, 0.7);
  border-radius: 6px;
}
</style>
